﻿using BW.Demo.Domain.Entities;
using BW.Demo.ErrorCode;
using BW.Demo.Infrastructure.Interfcaes;
using BW.Demo.WebApi.Applications.Commands.Deputy;
using MediatR;

namespace BW.Demo.WebApi.Applications.CommandHandlers.Deputy
{
    
    public class HealthQueryCommandHandler : IRequestHandler<HealthQueryCommand, APIResult<List<Health>>>
    {
        IBaseRespitory<Health> _respitory;
        public HealthQueryCommandHandler(IBaseRespitory<Health> _respitory)
        {
            this._respitory = _respitory;
        }
        public Task<APIResult<List<Health>>> Handle(HealthQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Health>> result = new APIResult<List<Health>>();
            result.Code = ResultCode.查询成功;
            result.Message = ResultCode.查询成功.ToString();
            var list = _respitory.GetAll().Where(x => x.Batch == request.Batch);
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
